package JZ42_和为S的两个数字;

import java.util.ArrayList;
public class Solution {
    public ArrayList<Integer> FindNumbersWithSum(int[] array,int sum) {
        ArrayList<Integer> list = new ArrayList<>();
        if (array.length < 1){
            return list;
        }
        int low = 0;
        int high = array.length - 1;

        while (low < high){
            int curSum = array[low] + array[high];

            if (curSum == sum){
                break;
            }else if (curSum > sum){
                high--;
            }else {
                low++;
            }
        }
        if (low != high) {
            list.add(array[low]);
            list.add(array[high]);
        }
        return list;
    }

    public static void main(String[] args) {
        int[] arr = {};
        int sum = 0;
        Solution solution = new Solution();
        ArrayList<Integer> list = solution.FindNumbersWithSum(arr, sum);
        System.out.println(list);
    }
}